#include<vector>
#include<map>
using namespace std;


class Solution {
public:
    vector<int> findDiagonalOrder(vector<vector<int>>& nums) {
        map<int, vector<int>>map_;
        for (int i = 0; i < nums.size(); ++i) {
            for (int j = 0; j < nums[i].size(); ++j) {
                map_[i + j].push_back(nums[i][j]);
            }
        }
        vector<int>res;
        for (auto& it : map_) {
            for (int i = it.second.size()-1; i >= 0; --i)
                res.push_back(it.second[i]);
        }
        return res;
    }
};